<template>
  <div class="news-item-wrapper" @click="gotoDetail">
    <ImgWithPlaceholder
      v-if="main"
      :img-src="imgSrc"
      :img-alt="content"
      width="100%"
      height="250px"
    />
    <p v-if="main" class="main-title">{{ title }}</p>
    <div class="brief-wrapper">
      <div class="date-column">
        <p class="date-column-year">{{ yearLabel }}</p>
        <p class="date-column-day">{{ monthHythenDay }}</p>
      </div>
      <div class="brief-column">
        <p v-if="!main" class="brief-title">{{ title }}</p>
        <p class="brief-content">{{ content }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import ImgWithPlaceholder from '@/components/ImgWithPlaceholder';

export default {
  components: {
    ImgWithPlaceholder,
  },
  props: {
    id: {
      type: Number,
      required: true,
    },
    title: {
      type: String,
      required: true,
    },
    content: {
      type: String,
      required: true,
    },
    publishedTs: {
      type: Number,
      required: true,
    },
    imgSrc: {
      type: String,
      default: null,
    },
    main: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    yearLabel() {
      return this.$utils.dt.getYear(this.publishedTs);
    },
    monthHythenDay() {
      return this.$utils.dt.getMonthHyphenDay(this.publishedTs);
    },
  },
  methods: {
    gotoDetail() {
      // console.log('>>>>wulala', this.id);
      this.$router.push({
        name: 'news-id',
        params: { id: this.id },
      });
    },
  },
};
</script>

<style scoped>
.news-item-wrapper {
  font-family: 'PingFangSC-Regular', 'PingFang SC';
  font-weight: 400;
  font-style: normal;
  text-align: left;
  line-height: 24px;
  letter-spacing: normal;
  text-transform: none;
  text-rendering: optimizeLegibility;
}
.news-item-wrapper:hover {
  cursor: pointer;
}
.main-title {
  font-size: 16px;
  color: #666;
  margin-left: 18px;
  margin-right: 24px;
  margin-top: 24px;
  margin-bottom: 24px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.brief-wrapper {
  width: 100%;
  height: 48px;
  max-height: 48px;
  display: flex;
  justify-content: stretch;
  align-items: center;
  margin-left: 18px;
  padding-right: 24px;
}
.date-column {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: stretch;
  padding-right: 24px;
}
.date-column-year {
  font-family: 'ArialMT', 'Arial';
  font-size: 20px;
  color: #666;
  margin: 0;
}
.date-column-day {
  font-family: 'ArialMT', 'Arial';
  font-size: 16px;
  color: #999;
  margin: 0;
}
.brief-column {
  height: 48px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding-left: 24px;
  border-left: 1px solid rgba(0, 0, 0, 0.125);
  overflow: hidden;
}
.brief-title {
  font-size: 16px;
  line-height: 28px;
  color: #666;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex-shrink: 0;
}
.brief-content {
  font-size: 12px;
  line-height: 24px;
  color: rgb(153, 153, 153);
  margin: 0;
}
</style>
